{include file='public/meta'}
<title>友情链接 - 插件管理 - 木鱼内容管理系统</title>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
		    		<div style="padding: 10px; background-color: #FAFAFA;">
              <div class="layui-row layui-col-space15">
                <div class="layui-col-md13">
                <div class="layui-card">
                    <div class="layui-card-header muyu-text">操作台&nbsp; &nbsp; &nbsp;<span class="muyu-tips-right">Tips:点击验证所有可检测所有对方友链是否上链</span></div>
                    <div class="layui-card-body" style="display:inline-block;">
                    <span style="display:inline-block;">选中项：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
					  <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="delurl()" href="javascript:;">批量删除</a>
					  <a class="layui-btn layui-btn-xs" onclick="checkurl()" href="javascript:;">验证所有</a>
					</div>
                    </div>
                    <div class="layui-card-body" style="display:inline-block;">
                    <span style="display:inline-block;">其他操作：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
					  <a class="layui-btn layui-btn-xs" onclick="openwind('添加友链','{:url('admin/Plug/linkcreate')}')" href="javascript:;">添加友链</a>
					</div>
                    </div>
                    </div>
                </div>
                </div>  
            </div>
		    <div style="padding: 10px 15px 20px 15px;">
            <span style="float:left;">共有数据：<span style="color:red;">{$list|count}</span> 条</span>
			<span style="float:right;margin-right: 20px;">未验证数据：<span style="color:red;">{$check}</span> 条</span>
			</div>
			<div class="layui-card-body">
            <div class="layui-table-body layui-table-main">
                <table class="layui-table" id="LAY-user-front-submit">
					<thead>
						<tr>
						    <th class=" layui-table-col-special">
							    <div class="layui-table-cell laytable-cell-checkbox">
							        <input type="checkbox" id="checkAll" onclick="isCheck()">
							    </div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>id</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>icon</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>站点名称</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>友链地址</span></div>
							</th>
							<!--<th>
								<div class="layui-table-cell" align="center"><span>友链简介</span></div>
							</th>-->
							<th>
								<div class="layui-table-cell" align="center"><span>创建时间</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>排序</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>状态</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>检测</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>操作</span></div>
							</th>
						</tr>
					</thead>
					<tbody>
					    {foreach $list as $val}
						<tr align="center">
						    <td class="layui-table-col-special">
								<input type="checkbox" name="fav" value="{$val.id}">
							</td>
							<td>{$val.id}</td>
							<td>{if condition="!empty($val.ico)"}
							<img style="border-radius: 50%;" height="46px" width="46px"  src="{$val.ico}">
							{/if}
							    
							    </td>
							<td>{$val.title}</td>
							<td>{$val.url}</td>
							<!--<td>{$val.intro}</td>-->
							<td>{$val.create_time|date='Y-m-d'}</td>
							<td>{$val.orders}</td>
							<td><div class="layui-table-cell">
                                      <a class="layui-btn-xs layui-btn layui-btn-{php}echo $val['status'] == '显示' ? 'btn' : 'danger';{/php}">{$val.status}</a>
                                </div>
                            </td>
                            <td>
                                <div class="layui-table-cell">
                                    <a onClick="checkurl('{$val.id}')" href="javascript:;" title="开始检查"><i class="layui-icon layui-icon-{if condition='$val.checkurl == NULL'}help{elseif condition='$val.checkurl == 1'}ok{else}close{/if}"></i>{if condition='$val.checkurl == NULL'}未检测{elseif condition='$val.checkurl == 1'}已上链{else}未上链{/if}</a>
                                </div>
                            </td>
							<td align="center"  class="layui-table-col-special">
								<div class="layui-table-cell">
								    <a class="layui-btn layui-btn-xs layui-btn-normal" onclick="linkstatus('{$val.id}')" href="javascript:;"><i class="layui-icon layui-icon-face-{php}echo $val['status'] == '显示' ? 'cry' : 'smile';{/php}"></i>{php}echo $val['status']=='显示' ? '隐藏':'显示';{/php}</a>
								    <a class="layui-btn layui-btn-xs" onclick="opennew('友链编辑','{:url('admin/Plug/linkedit',['id'=>$val.id])}')" href="javascript:;">编辑</a>
								    <a class="layui-btn layui-btn-xs layui-btn-warm" onclick="delurl('{$val.id}')" href="javascript:;">删除</a>
								    
								</div>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
            </div>
            <div class="layui-box layui-laypage layui-laypage-molv">{$list|raw}</div>
		</div>

	</div>


	<!-- 低部区域 -->
	{include file='public/footer'}
	<script>
		 // 全选 页面调用
            function isCheck(){
                var IsCheck= document.getElementById("checkAll");
                if(IsCheck.checked==false){
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=false;
                    }
                }
                if (IsCheck.checked==true) {
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=true;
                    }
                }
            }
        //删除操作    
        function delurl(id){
        var aid=$("tbody input:checkbox");
		var ids=[];
		if(id == null){
		id = allcheck(ids,aid);
		if(id !=""){
		  id = id.substring(0, id.length - 1);
		}
		}
		if(id !="" && id !=null){
		$.post("{:url('admin/Plug/linkdelete')}",{delid:id},function(data){
		        if(data.code === 1){
				layer.msg(data.msg, {time: 2000}, function() {
				location.reload();
					});
				}else{
				layer.msg(data.msg, {time: 2000});
				}
		    });
		}else{
		  layer.msg('当前未选择任何信息!',{icon:2,time:2000});  
		}
    }    
            //状态变更
        function linkstatus(id){
                layer.msg('确认要变更状态吗？', {
				time: 5000, //5s后自动关闭
				shade: 0.3,
				btn: ['确认', '取消'],
				yes: function() {
					//执行变更
					$.post("{:url('admin/Plug/linkstatus')}",{id:id}, function(data) {
					    if(data.code === 1){
					        layer.msg(data.msg, {time: 2000}, function() {
							location.reload();
						    });
					    }else{
					        layer.msg(data.msg, {time: 2000});
					    }
					})
    			   }
    			});
		}  
	
	function checkurl(id){
	    var index;
	    var ids=[];
	    var urlid=$("tbody input:checkbox");
	    if(id == null){
    	id = allcheck(ids,urlid);
    	if(id != ""){
    	id = id.substring(0, id.length - 1);
    	}	
	    }
	    if(id !="" && id !=null){
	       $.ajax({
	        type:"POST",
			data:{id:id},
			url:"{:url('admin/Plug/checkurl')}",
			dataType :"json",
			beforeSend: function() {
			    index = layer.load();
            },
			success:function(data){
				layer.msg(data.msg,{time:2000},function(){
					        //location.reload();
				if(data.code == 1){
                    location.reload(); //数据刷新
					}
				});
			},
			complete:function(){
			    layer.close(index);
            }
	    });
	    }else{
		  layer.msg('当前未选择任何信息!',{icon:2,time:2000});  
		}
	}
	
	function opennew(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		area: ['50%', '70%'],
		content: url,
		end:function(){
		    setTimeout(function(){ location.reload(); }, 2000);
		}
	});
	
    }

	</script>
</body>
</html>